package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 统计状态枚举
 */
public enum StatisticsStatus implements BaseEnum {

    PENDING("PENDING", "待计算"),
    PROCESSING("PROCESSING", "计算中"),
    COMPLETED("COMPLETED", "已完成"),
    FAILED("FAILED", "计算失败"),
    CANCELLED("CANCELLED", "已取消");

    private final String code;
    private final String description;

    StatisticsStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static StatisticsStatus fromCode(String code) {
        for (StatisticsStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown statistics status code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static StatisticsStatus fromDescription(String description) {
        for (StatisticsStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown statistics status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}